package com.vint.mi;

import java.util.Stack;

/**
 * 1.done
 * 2. stack easy
 *  判断括号是否合法，{[()]}
 */
public class Mi62 {
    public static String solution(String line){
        char[] src = line.toCharArray();
        Stack<Character> stack = new Stack<>();
        for(Character character : src){
            if(stack.isEmpty()){
                stack.add(character);
            }else{
                if(character==')'&&stack.peek()=='('){
                    stack.pop();
                    continue;
                }
                if(character==']'&&stack.peek()=='['){
                    stack.pop();
                    continue;
                }
                if(character=='}'&&stack.peek()=='{'){
                    stack.pop();
                    continue;
                }
                stack.add(character);
            }
        }
        if(stack.isEmpty()){
            return "1";
        }else{
            return "0";
        }
    }
    public static void main(String[] args) {
        System.out.println(solution("((([[]])))"));
        System.out.println(solution("(({[[]])))"));
    }
}
